library(ggplot2)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(lattice)
library(purrr)

1. Front data

frontdata=read.csv("~/Desktop/data-front.csv") # read the data into R
frontdata<-data.frame(frontdata)
#head(frontdata)
#names(frontdata)
#summary(frontdata)
frontdata$calf<- as.factor(frontdata$calf)
frontdata$calf<-as.factor(frontdata$calf)

frontdata<-tbl_df(frontdata)

Note that this dataset has already been cleaned a bit. Some data was removed when two images had <5 seconds between them and they were of the same calf, taken from the same angle. There is still some more tidying to be done, though.

frontdata %>%
  select(left_ear_average, image) %>%
  filter(left_ear_average<15) %>%
  arrange(desc(left_ear_average))
frontdata <- frontdata %>% 
  mutate(left_ear_average_clean = replace(left_ear_average, (left_ear_average < 20 & calf== "2193") | (left_ear_average < 20 & calf== "2203") | (left_ear_average < 20 & calf== "2220")| (left_ear_average < 20.5 & calf== "2188") | (left_ear_average < 15.5 & calf== "2224") | (left_ear_average < 20 & calf== "2236") | (left_ear_average < 20.5 & calf== "2237") | (left_ear_average < 19 & calf== "2229") | (left_ear_average < 10 & calf=="2121") | (left_ear_average < 15 & calf!="2121"), NA))

frontdata<- frontdata %>%
  mutate (left_ear_max_clean = if_else(left_ear_average_clean >0, left_ear_max, 0))

frontdata %>%
  select(right_ear_average, image) %>%
  filter(right_ear_average<15) %>%
  arrange(desc(right_ear_average))
frontdata <- frontdata %>%
  mutate (right_ear_average_clean = replace(right_ear_average, (right_ear_average < 19 & calf=="2229") | (right_ear_average < 20 & calf=="2188") | (right_ear_average < 20 & calf=="2203") | (right_ear_average < 20 & calf== "2236") | (right_ear_average < 20.5 & calf== "2237") | (right_ear_average < 10 & calf=="2121") | (right_ear_average < 15 & calf!="2121"), NA))


frontdata<- frontdata %>%
  mutate (right_ear_max_clean = if_else(right_ear_average_clean >0, right_ear_max, 0))

When processing images in FLIR Tools, there were some images where one or both ears weren’t properly visible so we instead put the “ear line” marker in a random, cold region of the image. After taking a look at the ear data, I am replacing any ear temperature values (max and average) from images that have an average ear temp < 15 with “NA”. I’m storing these in new variables with the suffix “_clean“. After applying this filter, there were some calves that had average ear temps > 15 that were not actually ear temperatures, so I looked at those cases one by one and cleaned them up (that’s why the mutate code up there is kinda big and specific).

frontdata<- frontdata %>%
  mutate(angle_and_direction_as_number = case_when(angle_and_direction=="L45"~"-45", angle_and_direction=="L30"~"-30", angle_and_direction=="L15"~"-15", angle_and_direction=="C0"~"0", angle_and_direction=="R15"~"15", angle_and_direction=="R30"~"30", angle_and_direction=="R45"~"45"))

frontdata$angle_and_direction_as_number<- as.factor(frontdata$angle_and_direction_as_number)

frontdata<- frontdata %>%
  mutate (elevation_and_direction_as_number = case_when(elevation_and_direction=="D30"~"-30", elevation_and_direction=="D15"~"-15", elevation_and_direction=="C0"~"0", elevation_and_direction=="U15"~"15", elevation_and_direction=="U30"~"30"))

frontdata$elevation_and_direction_as_number<- as.factor(frontdata$elevation_and_direction_as_number)

frontdata$angle_and_direction_as_number <- factor(frontdata$angle_and_direction_as_number,
    levels = c('-45','-30', '-15', '0', '15', '30', '45'),ordered = TRUE)

frontdata$elevation_and_direction_as_number <- factor(frontdata$elevation_and_direction_as_number,
    levels = c('-30', '-15', '0', '15', '30'),ordered = TRUE)

This is just to make the angles into integers (for ease of coding, they were originally stored as characters).

frontdata <- frontdata %>%
  select(image, calf, total_time_in_seconds, angle, direction, angle_and_direction_as_number, elevation, upwards_or_downwards,elevation_and_direction_as_number, stand_or_lie, left_ear_max_clean, left_ear_average_clean, right_ear_max_clean, right_ear_average_clean, left_nostril_max, left_nostril_average, right_nostril_max, right_nostril_average, left_airway_max, left_airway_average, right_airway_max, right_airway_average, muzzle_max, muzzle_average, hair_whorl_max)

I’m just choosing/reordering the columns here so the code is more efficient later on.

1.1 Temperature and time

hist(frontdata$total_time_in_seconds, breaks=30, main = "Number of images vs. time in trial")

under300<- subset(frontdata, total_time_in_seconds<300)
length(frontdata$total_time_in_seconds) #817
## [1] 817
length(which(frontdata$total_time_in_seconds > 300)) #70
## [1] 70
length(which(frontdata$total_time_in_seconds < 300)) #747
## [1] 747

The test is supposed to be 5 minutes (300 seconds) long, but a histogram shows that we have quite a few images that are timestamped past the 300s mark. 70 of the 817 images, nearly 10%, are over 300s.

Does temperature change during the 5 minute filming period?

#plot(frontdata$total_time_in_seconds, frontdata$hair_whorl_max, col=frontdata$calf)

ggplot(data = frontdata, aes(x = total_time_in_seconds, y = hair_whorl_max, group = calf, colour=calf)) + geom_line()

These plots are pretty hard to understand, so I’m going to make some lattice plots instead where you can see each calf separately.

# I followed this tutorial to automate the: https://aosmith.rbind.io/2018/08/20/automating-exploratory-plots/

response<- names(frontdata[11:25])
response = set_names(response)
#response

lattice_plots = function(x, y) {
     ggplot(frontdata, aes_string(x = x, y = y)) +
          geom_line() + facet_wrap(~calf) +
          labs(x = x,
               y = y) + 
    ggtitle(y)
}

exploratory_time_plots = map(response, ~lattice_plots(y=.x, "total_time_in_seconds") )

#names(exploratory_time_plots)

exploratory_time_plots
## $left_ear_max_clean

## 
## $left_ear_average_clean

## 
## $right_ear_max_clean

## 
## $right_ear_average_clean

## 
## $left_nostril_max

## 
## $left_nostril_average

## 
## $right_nostril_max

## 
## $right_nostril_average

## 
## $left_airway_max

## 
## $left_airway_average

## 
## $right_airway_max

## 
## $right_airway_average

## 
## $muzzle_max

## 
## $muzzle_average

## 
## $hair_whorl_max

It seems that in general, individuals’ temperatures are not changing much across time.

1.2 Angles

Note that some variables relating to angles have been cleaned in a previous section.

How many images do we have of the calves from each angle? First, taken from the left or right:

ggplot(frontdata, aes(x=as.factor(angle_and_direction_as_number) )) + geom_bar() + ggtitle("Front images, with calves showing more of the left (-) to right (+) side of their faces")+ theme(plot.title = element_text(hjust = 0.5))

So we have many images of the calves taken from the front, and less taken from angles. Interestingly, there are also more pictures taken fron the calves’ right sides.

Does temperature change depending on the angle?

For the following plots, the upper whisker extends from the hinge to the highest value that is within 1.5 x IQR of the hinge, where IQR is the inter-quartile range, or distance between the first and third quartiles. The lower whisker extends from the hinge to the lowest value within 1.5 x IQR of the hinge. Data beyond the end of the whiskers are outliers and plotted as points (as specified by Tukey).

#ggplot(frontdata, aes(x=as.factor(angle_and_direction_as_number), y = right_ear_average_clean )) + geom_boxplot() + ggtitle("Avg temperature of right ear + angle of picture")+ theme(plot.title = element_text(hjust = 0.5))

angle_boxplots = function(x, y) {
     ggplot(frontdata, aes_string(x = x, y=y)) +
    geom_boxplot() + 
    labs(x = x, y = y) + 
    ggtitle(y)
}

exploratory_angle_plots = map(response, ~angle_boxplots(y=.x, x= "angle_and_direction_as_number") )

#names(exploratory_angle_plots)

exploratory_angle_plots
## $left_ear_max_clean
## Warning: Removed 131 rows containing non-finite values (stat_boxplot).

## 
## $left_ear_average_clean
## Warning: Removed 131 rows containing non-finite values (stat_boxplot).

## 
## $right_ear_max_clean
## Warning: Removed 63 rows containing non-finite values (stat_boxplot).

## 
## $right_ear_average_clean
## Warning: Removed 63 rows containing non-finite values (stat_boxplot).

## 
## $left_nostril_max

## 
## $left_nostril_average

## 
## $right_nostril_max

## 
## $right_nostril_average

## 
## $left_airway_max

## 
## $left_airway_average

## 
## $right_airway_max

## 
## $right_airway_average

## 
## $muzzle_max

## 
## $muzzle_average

## 
## $hair_whorl_max

So in general, it seems that the sideways angle doesn’t matter much.

Now, of the calves looking down or up. How many do we have from each angle (here called “elevation” to avoid confusion with the sideways angles)?

ggplot(frontdata, aes(x=elevation_and_direction_as_number)) + geom_bar() + ggtitle("Number of frontal images, calves looking down or up") + theme(plot.title = element_text(hjust = 0.5))

Most of the images were taken from above the calf (so we are looking down at the calf, versus looking at it head-on or looking up its snout).

angle_boxplots = function(x, y) {
     ggplot(frontdata, aes_string(x = x, y=y)) +
    geom_boxplot() + 
    labs(x = x, y = y) + 
    ggtitle(y)
}

exploratory_elevation_plots = map(response, ~angle_boxplots(y=.x, x= "elevation_and_direction_as_number") )

#names(exploratory_angle_plots)

exploratory_elevation_plots
## $left_ear_max_clean
## Warning: Removed 131 rows containing non-finite values (stat_boxplot).

## 
## $left_ear_average_clean
## Warning: Removed 131 rows containing non-finite values (stat_boxplot).

## 
## $right_ear_max_clean
## Warning: Removed 63 rows containing non-finite values (stat_boxplot).

## 
## $right_ear_average_clean
## Warning: Removed 63 rows containing non-finite values (stat_boxplot).

## 
## $left_nostril_max

## 
## $left_nostril_average

## 
## $right_nostril_max

## 
## $right_nostril_average

## 
## $left_airway_max

## 
## $left_airway_average

## 
## $right_airway_max

## 
## $right_airway_average

## 
## $muzzle_max

## 
## $muzzle_average

## 
## $hair_whorl_max

1.3 Relation between different ROIs

mean_data<- under300 %>%
  group_by(calf) %>%
  mutate_at(vars(11:25), .funs= mean, na.rm=T)

#colnames(mean_data)

all_data<- cbind(under300, mean_data[11:25])
#names(all_data)

for(i in 26:40){ 
  names(all_data)[i] <- paste(names(all_data)[i], "mean", sep="_")
}

#all_data
#names(all_data)

all_data_front <- mutate(all_data, left_ear_max_clean_centered = left_ear_max_clean_mean - left_ear_max_clean, 
        left_ear_average_clean_centered = left_ear_average_clean_mean - left_ear_average_clean,
        right_ear_max_clean_centered = right_ear_max_clean_mean - right_ear_max_clean,
        right_ear_average_clean_centered = right_ear_average_clean_mean - right_ear_average_clean,
        left_nostril_max_centered = left_nostril_max_mean - left_nostril_max,
        left_nostril_average_centered = left_nostril_average_mean - left_nostril_average,
        right_nostril_max_centered = right_nostril_max_mean - right_nostril_max,
        right_nostril_average_centered = right_nostril_average_mean - right_nostril_average,
        left_airway_max_centered = left_airway_max_mean - left_airway_max,
        left_airway_average_centered = left_airway_average_mean - left_airway_average,
        right_airway_max_centered = right_airway_max_mean - right_airway_max,
        right_airway_average_centered = right_airway_average_mean - right_airway_average,
        muzzle_max_centered = muzzle_max_mean - muzzle_max,
        muzzle_average_centered = muzzle_average_mean - muzzle_average,
        hair_whorl_max_centered = hair_whorl_max_mean - hair_whorl_max
        )

#names(all_data_front)
#all_data_front

frontdata_means <- all_data_front %>%
  dplyr::select(contains("_mean")) %>%
  dplyr::select(matches("average|whorl"))
                
#names(frontdata_means)

splom(frontdata_means, main= "Between-indiv. association between ROIs (data averaged per indiv.)")

names(frontdata_means)
## [1] "left_ear_average_clean_mean"  "right_ear_average_clean_mean"
## [3] "left_nostril_average_mean"    "right_nostril_average_mean"  
## [5] "left_airway_average_mean"     "right_airway_average_mean"   
## [7] "muzzle_average_mean"          "hair_whorl_max_mean"
frontdata_centered <- all_data_front %>%
  dplyr::select(contains("_centered")) %>%
  dplyr::select(matches("average|whorl"))

splom(frontdata_centered, main= "Within-indiv. association between ROIs (data centered by indiv.)", varname.cex = .5, xlab.cex = .2)

names(frontdata_centered)
## [1] "left_ear_average_clean_centered"  "right_ear_average_clean_centered"
## [3] "left_nostril_average_centered"    "right_nostril_average_centered"  
## [5] "left_airway_average_centered"     "right_airway_average_centered"   
## [7] "muzzle_average_centered"          "hair_whorl_max_centered"

1.4 Does temperature correlate with number of images taken (could it be a proxy for reaction towards an experimenter?)

under300<- under300%>%
  mutate(angle_and_direction_numeric = as.numeric(angle_and_direction_as_number))

t <-under300 %>%
  dplyr::select(calf, angle_and_direction_numeric, 13:25) %>% 
  group_by(calf) %>%
  summarise_all(funs(mean))

t<- cbind(count(frontdata, calf), t)
#t
#names(t)

for(i in 4:15){
  plot(t$n, t[[i]], xlab="Number of front images per individual", ylab=names(t[i]), main="No. of images vs. ROI temperature in 5 minutes of filming")
}

plot(t$n, ((t$angle_and_direction_numeric-3)*15), sub = "values below 0 correspond to showing the left side, above 0 the right side", ylab= "Average degrees each calf faced to the left(-) or right (+) ", main= "No. images vs. side angle of head (in 5 minutes)",  ylim=c(-10,30), xlim=c(5,60))

It seems that when a calf has many usable images, it tends to be quite warm (although there is one particular calf with many images and a high temperature, and although it makes the relationship “nicer”, it doesn’t seem to be carrying it all by itself).

frontdata %>%
  group_by(calf)%>%
  summarise(mean_angle = mean(as.numeric(angle_and_direction_as_number)))

1.5 Distribution of temperatures

for(i in 11:25){
  hist(frontdata[[i]], breaks=20, main=paste(names(frontdata[i])))
}

2 Back data

backdata=read.csv("~/Desktop/data-back.csv") # read the data into R
backdata<-data.frame(backdata)
#head(backdata)
#names(backdata)
#summary(backdata)
backdata$calf<- as.factor(backdata$calf)

backdata<-tbl_df(backdata)
backdata <- backdata %>%
  select(-Filename)

Does temperature of the ears as seen from behind change across the 5 minute test?

backdata<- backdata %>%
  mutate(angle_and_direction_as_number = case_when(angle_and_direction=="L60"~"-60", angle_and_direction=="L45"~"-45", angle_and_direction=="L30"~"-30", angle_and_direction=="L15"~"-15", angle_and_direction=="C0"~"0", angle_and_direction=="R15"~"15", angle_and_direction=="R30"~"30", angle_and_direction=="R45"~"45", angle_and_direction=="R60"~"60"))

backdata$angle_and_direction_as_number<- as.factor(backdata$angle_and_direction_as_number)

backdata<- backdata %>%
  mutate (elevation_and_direction_as_number = case_when(elevation_and_direction=="30D"~"-30", elevation_and_direction=="15D"~"-15", elevation_and_direction=="0C"~"0", elevation_and_direction=="15U"~"15", elevation_and_direction=="30U"~"30"))

backdata$elevation_and_direction_as_number<- as.factor(backdata$elevation_and_direction_as_number)

backdata$angle_and_direction_as_number <- factor(backdata$angle_and_direction_as_number,
    levels = c('-60', '-45','-30', '-15', '0', '15', '30', '45', '60'),ordered = TRUE)

backdata$elevation_and_direction_as_number <- factor(backdata$elevation_and_direction_as_number,
    levels = c('-30', '-15', '0', '15', '30'),ordered = TRUE)

This is just to make the angles into integers that go from negative to positive/ left to right/down to up.

2.1 Temperature and time

hist(backdata$total_time_in_seconds, breaks=30, main = "Number of images vs. time in trial")

under300_back<- subset(backdata, total_time_in_seconds<300)
length(backdata$total_time_in_seconds) #447
## [1] 447
length(which(backdata$total_time_in_seconds > 300)) #100
## [1] 100
length(which(backdata$total_time_in_seconds < 300)) #347
## [1] 347

The test is supposed to be 5 minutes (300 seconds) long, but a histogram shows that we have quite a few images that are timestamped past the 300s mark. 100 of the 447 images, ~22%, are over 300s.

ggplot(data = backdata, aes(x = total_time_in_seconds, y = right_ear_average, group = calf, colour=calf)) + geom_line()

# I followed this tutorial to automate the: https://aosmith.rbind.io/2018/08/20/automating-exploratory-plots/

backresponse<- names(backdata[8:11])
backresponse = set_names(backresponse)
#backresponse

lattice_plots = function(x, y) {
     ggplot(backdata, aes_string(x = x, y = y)) +
          geom_line() + facet_wrap(~calf) +
          labs(x = x,
               y = y) + 
    ggtitle(paste("Back data",y, sep=" "))
}

back_exploratory_time_plots = map(backresponse, ~lattice_plots(y=.x, "total_time_in_seconds") )

#names(exploratory_time_plots)

back_exploratory_time_plots
## $left_ear_average

## 
## $left_ear_max

## 
## $right_ear_average

## 
## $right_ear_max

2.2 Angles

ggplot(backdata, aes(x=angle_and_direction_as_number)) + geom_bar() + ggtitle("Number of back images, calves showing more of their left(-) or right (+) side") + theme(plot.title = element_text(hjust = 0.5))

#names(backdata)

backresponse<- names(backdata[8:11])
backresponse = set_names(backresponse)
#backresponse

angle_boxplots = function(x, y) {
     ggplot(backdata, aes_string(x = x, y=y)) +
    geom_boxplot() + 
    labs(x = x, y = y) + 
    ggtitle(paste("Back data", y, sep=" "))
}

back_exploratory_angle_plots = map(backresponse, ~angle_boxplots(y=.x, x= "angle_and_direction_as_number") )

#names(exploratory_angle_plots)

back_exploratory_angle_plots
## $left_ear_average

## 
## $left_ear_max

## 
## $right_ear_average

## 
## $right_ear_max

ggplot(backdata, aes(x=elevation_and_direction_as_number)) + geom_bar() + ggtitle("Number of back images, taken from below (-) or above (+)") + theme(plot.title = element_text(hjust = 0.5))

back_exploratory_elevation_plots = map(backresponse, ~angle_boxplots(y=.x, x= "elevation_and_direction_as_number") )

back_exploratory_elevation_plots
## $left_ear_average

## 
## $left_ear_max

## 
## $right_ear_average

## 
## $right_ear_max

3 Side data

sidedata=read.csv("~/Desktop/data-side.csv") # read the data into R
sidedata<-data.frame(sidedata)
#head(sidedata)
#names(sidedata)
#summary(sidedata)
sidedata$calf<- as.factor(sidedata$calf)

sidedata<-tbl_df(sidedata)
#head(sidedata)
sideresponse<- names(sidedata[7:10])
sideresponse = set_names(sideresponse)

lattice_plots = function(x, y) {
     ggplot(sidedata, aes_string(x = x, y = y)) +
          geom_line() + facet_wrap(~calf) +
          labs(x = x,
               y = y) + 
    ggtitle(paste("Side",y, sep=" "))
}

side_exploratory_time_plots = map(sideresponse, ~lattice_plots(y=.x , "total_time_in_seconds"))

#names(exploratory_time_plots)

side_exploratory_time_plots
## $eyeball_average

## 
## $inner_corner_eye_max

## 
## $rostral_eye_surrounding_max

## 
## $caudal_eye_surrounding_max

names(sidedata)
##  [1] "image"                       "calf"                       
##  [3] "minutes"                     "seconds"                    
##  [5] "miliseconds"                 "total_time_in_seconds"      
##  [7] "eyeball_average"             "inner_corner_eye_max"       
##  [9] "rostral_eye_surrounding_max" "caudal_eye_surrounding_max" 
## [11] "angle"                       "direction"                  
## [13] "angle_and_direction"         "temperature"                
## [15] "humidity"                    "THI"                        
## [17] "side"
sidedata
sidedata$angle_and_direction
##    [1] 45F 30F 15F 30F 45F 60F 60F 30F 15B 0C  15F 30F 15B 30F 15F 15B 30B
##   [18] 60F 30F 30B 15F 30F 30B 15B 0C  30F 15B 30B 0C  15B 0C  45F 30F 0C 
##   [35] 45F 30F 45F 0C  30F 45F 45F 30F 0C  45F 30F 30F 45F 45F 15B 30B 0C 
##   [52] 0C  30F 15B 15B 15B 0C  15B 15B 0C  0C  15B 0C  15F 15B 60F 15F 0C 
##   [69] 15F 15F 0C  45F 30F 15B 30F 15F 0C  0C  45F 15F 45F 30F 0C  15B 30B
##   [86] 15B 0C  15B 45F 30F 15F 15F 0C  15B 15B 15B 0C  45F 45F 15B 0C  45F
##  [103] 30F 45F 0C  15B 0C  45F 60F 30F 15F 60F 15B 30F 15B 45F 60F 45F 30F
##  [120] 45F 15B 30F 15B 0C  15B 0C  30F 60F 30F 15F 45F 45F 30F 15F 0C  15B
##  [137] 15B 15F 15B 45F 60F 45F 45F 45F 30F 30F 0C  0C  15F 0C  15F 45F 45F
##  [154] 30F 15B 0C  45F 30F 0C  30F 15F 15F 0C  15B 30F 45F 30F 0C  45F 30F
##  [171] 15F 0C  60F 45F 30F 0C  15F 0C  15B 0C  15F 30F 45F 30F 15F 15B 45F
##  [188] 30F 15F 60F 45F 60F 15F 45F 30F 0C  15F 45F 45F 30F 30B 15B 0C  15B
##  [205] 30B 0C  15B 45F 30B 30F 15F 15F 0C  60F 45F 15F 0C  15B 45F 60F 45F
##  [222] 30F 15B 0C  60F 30F 0C  45F 30F 15F 15B 30B 60F 30F 15F 0C  30F 15B
##  [239] 15B 15F 0C  60F 45F 15F 0C  0C  30F 45F 15F 45F 15F 0C  30F 60F 45F
##  [256] 30F 15F 30F 30F 60F 30F 15F 0C  30B 15B 15F 45F 45F 15F 30F 0C  15B
##  [273] 30F 60F 30F 0C  15B 45F 0C  30F 15B 45F 60F 60F 45F 15B 0C  30F 15F
##  [290] 30F 15F 0C  15B 15F 0C  15B 60F 30F 15F 0C  15B 30F 15B 0C  60F 60F
##  [307] 45F 30F 0C  15B 0C  0C  15B 30B 15B 0C  30F 45F 60F 60F 45F 30F 0C 
##  [324] 15B 45F 0C  15B 60F 60F 30F 60F 45F 60F 45F 15F 0C  15F 30F 15F 15B
##  [341] 0C  60F 45F 30F 15F 0C  15B 30F 15F 0C  15B 45F 60F 45F 30F 15F 0C 
##  [358] 15B 0C  45F 30F 15F 15B 30B 15B 30F 15F 15B 0C  15B 30F 45F 30F 15F
##  [375] 60F 45F 30F 15F 0C  0C  30F 45F 30F 30B 15B 0C  15F 0C  15B 15F 0C 
##  [392] 15B 0C  15F 45F 60F 15B 60F 45F 30F 60F 0C  45F 15F 0C  15B 30B 30F
##  [409] 45F 30F 45F 60F 60F 45F 30F 60F 45F 0C  15F 60F 60F 30F 60F 60F 45F
##  [426] 30F 15F 45F 60F 30F 15B 0C  0C  15F 30F 45F 60F 15F 0C  15B 45F 60F
##  [443] 30F 15F 0C  15B 0C  15F 45F 30F 15F 0C  30F 45F 60F 15F 30F 45F 0C 
##  [460] 15F 30F 45F 60F 15B 15F 30F 45F 60F 45F 30F 15F 0C  45F 60F 15B 0C 
##  [477] 15F 30F 45F 60F 45F 30F 0C  15B 30B 0C  45F 60F 45F 60F 45F 45F 30F
##  [494] 15F 0C  15B 30B 15F 30F 45F 60F 45F 30F 15F 30F 15F 0C  15B 45F 15B
##  [511] 15F 0C  15B 30B 0C  30F 0C  15B 0C  30F 45F 45F 45F 30F 15F 0C  15B
##  [528] 30B 15B 15F 30F 15B 0C  30F 45F 30F 45F 0C  15B 0C  15F 30F 45F 60F
##  [545] 60F 45F 30F 15F 15F 45F 60F 60F 60F 45F 30F 15F 15F 30F 45F 60F 15B
##  [562] 45F 60F 45F 30F 15F 0C  15B 30B 0C  30F 45F 60F 45F 15F 30F 60F 45F
##  [579] 0C  15B 15F 15B 15F 45F 15B 30B 15F 45F 15B 0C  30F 45F 45F 30F 15F
##  [596] 0C  15B 0C  0C  30F 45F 30F 15B 60F 0C  15F 30F 45F 60F 45F 60F 45F
##  [613] 30F 15F 0C  15B 45F 15F 15B 45F 30F 30F 0C  15F 45F 30F 45F 60F 60F
##  [630] 45F 15F 0C  15B 45F 30F 0C  60F 60F 45F 30F 15F 0C  15B 30F 45F 45F
##  [647] 30F 15F 0C  60F 45F 45F 15F 15B 15B 0C  15F 0C  15F 45F 30F 60F 45F
##  [664] 30F 15F 0C  30B 15B 15F 15B 30B 15B 30F 45F 30F 15F 15B 0C  15F 60F
##  [681] 45F 45F 30F 15F 15B 45F 30F 45F 15F 15B 45F 30F 60F 30F 0C  60F 30F
##  [698] 45F 60F 45F 0C  15B 45F 30F 45F 15F 15F 15B 60F 45F 30F 15F 15B 0C 
##  [715] 15F 0C  30F 45F 60F 15F 15B 0C  15F 30F 0C  60F 60F 45F 30F 30F 45F
##  [732] 60F 45F 30F 15B 0C  15F 60F 30F 45F 15F 0C  30F 45F 60F 0C  30F 60F
##  [749] 0C  30F 60F 30F 45F 15F 45F 15B 30F 15F 0C  0C  45F 30F 15B 30B 30F
##  [766] 15F 15B 0C  0C  45F 45F 30F 0C  30F 0C  30F 0C  30B 45F 0C  0C  15F
##  [783] 45F 30F 0C  15B 45F 0C  60F 15B 0C  30F 15F 0C  0C  0C  15B 15B 0C 
##  [800] 15F 30F 15F 0C  30F 15F 0C  15B 15F 15B 30B 15B 30B 30B 15B 15B 0C 
##  [817] 30F 0C  15B 0C  15B 15B 0C  0C  15B 0C  30F 0C  30F 15B 30F 45F 15F
##  [834] 45F 15B 30B 15B 30B 30B 30F 15B 30F 0C  15B 0C  0C  15B 15B 30B 15B
##  [851] 15B 30B 30F 15B 0C  15B 0C  45F 15F 0C  0C  30F 15B 15B 30F 0C  45F
##  [868] 30F 0C  45F 30F 15B 15B 0C  45F 45F 60F 30F 15B 0C  15B 0C  15F 30F
##  [885] 15B 15F 30F 15F 0C  15B 45F 30F 0C  30B 15F 30B 15B 15B 30B 15B 0C 
##  [902] 0C  60F 30F 15F 30F 45F 30F 15F 45F 30F 15F 0C  15B 60F 45F 30F 0C 
##  [919] 30F 45F 30F 15F 15B 0C  0C  15F 30F 30F 15B 30B 30B 15B 45F 0C  30B
##  [936] 0C  15B 15B 0C  30F 30F 45F 15F 15B 30B 15B 0C  30F 45F 30F 0C  15B
##  [953] 15B 0C  45F 0C  15F 30F 0C  15F 30F 30F 45F 30F 0C  15F 15F 30F 0C 
##  [970] 30F 15F 15B 0C  0C  15F 15B 0C  30F 45F 45F 30F 60F 15B 15B 0C  15F
##  [987] 0C  15B 15B 15B 15B 0C  15B 0C  15F 15B 15F 30F 0C  15B 60F 45F 30F
## [1004] 15F 0C  60F 45F 45F 30F 15F 0C  45F 30F 15B 15B 0C  30F 15F 30B 0C 
## [1021] 15B 0C  45F 15F 15B 0C  15B 0C  15F 30F 0C  30B 15B 30B 0C  0C  15B
## [1038] 0C  30B 15B 30B 15B 30B 15B 15F 15B 0C  15B 15F 0C  15B 30F 15F 0C 
## [1055] 15B 15B 45F 45F 0C  45F 30F 0C  30F 45F 30F 15F 0C  15B 15B 0C  30B
## [1072] 0C  30F 45F 30B 15B 60F 45F 30F 15B 15B 0C  45F 15F 0C  15F 45F 60F
## [1089] 45F 30F 15F 15F 0C  15B 45F 60F 30F 15F 15B 45F 30F 15F 0C  15B 45F
## [1106] 30F 45F 30F 15F 0C  15B 30B 0C  30F 45F 15F 15B 30B 30F 15F 0C  15F
## [1123] 30F 45F 60F 45F 30F 15F 0C  30F 45F 60F 15B 0C  15F 30F 30F 0C  15B
## [1140] 15F 30F 15F 0C  15B 15F 45F 30F 45F 30F 15F 0C  15F 30F 45F 60F 30F
## [1157] 30F 45F 45F 15F 15F 30F 15F 0C  15B 0C  15F 30F 45F 30F 45F 45F 30F
## [1174] 45F 30F 15F 0C  15B 0C  15B 0C  0C  0C  15B 30F 15F 0C  15F 15B 30B
## [1191] 30F 0C  30F 45F 60F 45F 30F 45F 30F 30F 45F 0C  0C  15F 30F 15F 45F
## [1208] 60F 45F 15F 0C  15B 60F 45F 30F 15F 0C  15B 15B 15B 0C  15F 0C  15B
## [1225] 0C  15F 15F 30F 45F 45F 15F 0C  30F 45F 0C  60F 45F 30F 15F 0C  0C 
## [1242] 15F 30F 45F 30F 15F 30F 45F 30F 15F 0C  15B 30B 45F 30F 15F 0C  15B
## [1259] 30B 15B 0C  45F 30F 15F 0C  15B 15F 0C  15B 30B 0C  15B 30B 30F 15F
## [1276] 30B 15B 0C  45F 60F 45F 30F 30F 0C  0C  15B 30B 15F 30F 30B 15B 0C 
## [1293] 30F 45F 45F 15F 0C  15B 15F 45F 60F 45F 15F 0C  30B 15B 0C  0C  45F
## [1310] 30F 30F 45F 0C  15F 0C  0C  15F 0C  15F 15F 0C  0C  0C  45F 30F 60F
## [1327] 45F 45F 30F 0C  15F 30F 45F 60F 30F 15F 0C  15F 0C  45F 0C  30B 15B
## [1344] 0C  45F 45F 30F 15F 0C  15F 0C  30B 15B 0C  15B 45F 30F 15F 0C  15B
## [1361] 30B 15F 15B 0C  15F 0C  15F 30F 45F 60F 15F 0C  15F 30F 45F 45F 30F
## [1378] 15F 15B 30B 15F 30F 15F 15F 30F 60F 45F 45F 30F 15F 0C  15B 30F 45F
## [1395] 45F 45F 30F 15F 0C  45F 45F 30F 15F 45F 15F 0C  15F 60F 0C  15F 30F
## [1412] 60F 45F 0C  30F 0C  0C  15F 30F 0C  15F 30F 30B 0C  15B 15F 30B 45F
## [1429] 15F 15B 45F 15F 15B 0C  45F 30F 30F 45F 30F 15F 15B 0C  15F 15F 0C 
## [1446] 30B 15F 0C  30F 45F 30F 0C  15B 45F 45F 30F 15F 30B 30F 15F 0C  15B
## [1463] 15F
## Levels: 0C 15B 15F 30B 30F 45F 60F
sidedata<- sidedata %>%
  mutate(angle_and_direction_as_number = case_when(angle_and_direction=="60B"~"-60", angle_and_direction=="45B"~"-45", angle_and_direction=="30B"~"-30", angle_and_direction=="15B"~"-15", angle_and_direction=="0C"~"0", angle_and_direction=="15F"~"15", angle_and_direction=="30F"~"30", angle_and_direction=="45F"~"45", angle_and_direction=="60F"~"45"))

sidedata$angle_and_direction_as_number <- factor(sidedata$angle_and_direction_as_number,
    levels = c('-60', '-45','-30', '-15', '0', '15', '30', '45', '60'),ordered = TRUE)

ggplot(sidedata, aes(x=angle_and_direction_as_number)) + geom_bar() + ggtitle("Number of side images, from the back (-) to the front (+)") + theme(plot.title = element_text(hjust = 0.5))

#sideunder300<- subset(sidedata, total_time_in_seconds<300)

#sideunder300<- sideunder300%>%
#  mutate(angle_and_direction_numeric = as.numeric(angle_and_direction_as_number))

#names(sideunder300)

#t <-sideunder300 %>%
#  dplyr::select(calf, angle_and_direction_numeric, 7:10) %>% 
#  group_by(calf) %>%
#  summarise_all(funs(mean))

#t<- cbind(count(sideunder300, calf), t)
#t
#names(t)

#for(i in 7:10){
#  plot(t$n, t[[i]], xlab="Number of side images per individual", ylab=names(t[i]), main="No. of images vs. ROI temperature in 5 minutes of filming")
#}

#plot(t$n, ((t$angle_and_direction_numeric-3)*15), sub = "values below 0 correspond to showing the left side, above 0 the right side", ylab= "Average degrees each calf faced to the left(-) or right (+) ", main= "No. images vs. side angle of head (in 5 minutes)",  ylim=c(-10,30), xlim=c(5,60)) + abline(h=0, col="blue")